home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: Pointer arithmetic
- Date: 29 Feb 1996 16:37:47 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Feb29093747@qcd.lanl.gov>
- References: <4h2r55$er@s3.iway.fr>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: Pascal Terracol's message of 29 Feb 1996 00:14:28 GMT
-
- In article <4h2r55$er@s3.iway.fr>
- Pascal Terracol <assetsto@pratique.fr> writes:
-
- PT: Hello,
- PT:
- PT: this sample code have been correctly working on a pc 80286 processor
- PT:
- PT: I put it on a mac and the pointers seems to act differently...
- PT: any idea about that ?
-
- Usually means the code was not C to start with: it was using any
- sequence of symbols which was not detected as an error by the compiler
- in question.
-
- Sometimes, it is valid, but implementation dependent C.
-
- PT:
- PT:
- PT: int size, n1, n2 ;
- PT: Point *p_debut, *p1, *p2 ;
- /* "vecteur" de translation des adr */
- PT:
- PT: ...
- PT:
- PT: n1 = (int) (l->p1)/sizeof(Point) ;
- PT: n2 = (int) (l->p2)/sizeof(Point) ;
-
- What is l? If you are having a problem, why can't you ask the question
- with a short compilable piece of code? Why do you expect us to spend
- our time extracting meaning from a garbled piece of non-code, so that
- we can help you?
-
- In any case, assuming (l->p1) is a Point*, there is no guarantee what
- (int)(l->p1)/sizeof(Point) gives. Do not use such a construct: in fact
- trying to convert a pointer to int may even crash some machine. If you
- know that l->p1 points into some array and l->p0 is the beginning of
- that array, write n1 = (l->p1 - l->p0). Instead why not store the
- array index in l?
-
-
- PT:
- PT: p1 = p_debut + n1 ;
- PT: p2 = p_debut + n1 ;
- PT: ...
- PT:
- PT: is there a cast solution ?
-
- I have absolutely no idea what you mean by this question. Try to avoid
- casts when you write code: most of what a beginner does with casts is
- based on misunderstanding.
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-